<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
#use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (Schema::hasTable('user_sms')) return;
        Schema::create('user_sms', function (Blueprint $table) {
            $table->id();
            $table->char('mobile', 11)->default('')->comment('发送手机号');
            $table->char('sms', 6)->default('')->comment('验证码');
            $table->tinyInteger('type')->default(1)->comment('验证码类型');
            $table->integer('expire_at')->default(0)->comment('过期时间戳');
            $table->boolean('status')->default(0)->comment('使用状态：1已使用，0未使用');
            $table->string('client_ip')->default('')->comment('客户端ip地址');
            $table->dateTime('created_at')->default(\DB::raw('CURRENT_TIMESTAMP'));
            $table->timestamp('updated_at')->default(\DB::raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'));
            $table->index('created_at');
            $table->index('mobile');
        });
        DB::statement("ALTER TABLE `user_sms` COMMENT '短信验证码'");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        if (!is_production()) Schema::dropIfExists('user_sms');
    }
};
